DECLARE @xml XML

SET @xml = 
    (
        SELECT
            FragmentId
        ,   FragmentName        = ISNULL(FragmentName,'')
        ,   FragmentDisplayName = CAST('<![CDATA[' + ISNULL(FragmentDisplayName,'') + ']]>' AS xml)
        ,   SortOrdinal         = ISNULL(CAST(SortOrdinal AS varchar(16)),'')
        ,   CreateDate          = ISNULL(Core.dbo.fDateFormat(@GlobalDateFormat,CreateDate),'')
        ,   EndDate             = ISNULL(CAST(EndDate AS varchar(64)),'')
        ,   ModificationDate    = ISNULL(CAST(ModificationDate AS varchar(64)),'')
        ,   DocumentId          = ISNULL(CAST(DocumentId AS varchar(16)),'')
        ,   PrevFragmentId      = ISNULL(CAST(PrevFragmentId AS varchar(16)),'')
        ,   NextFragmentId      = ISNULL(CAST(NextFragmentId AS varchar(16)),'')
        ,   IsPrevious          = ISNULL(IsPrevious,0)
        ,   IsNext              = ISNULL(IsNext,0)
        ,   IsWrapper           = ISNULL(IsWrapper,0)
        ,   ClientId            = ISNULL(ClientId,'')
        ,   IsActive            = ISNULL(IsActive,0)
        ,   FragmentWrapper     = CAST(dbo.fGetWebXmlString('FragmentWrapper',FragmentId) AS xml)
        FROM
            Fragment
        WHERE
            DocumentId = @DocumentId
        FOR XML AUTO, ELEMENTS, ROOT('ChildFragments')
  )

SELECT @xml
